﻿using System.Windows.Input;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

using FanaticToy.Core;

namespace FanaticToy.UI.ViewModels
{
    ///<summary>原数据的视图。</summary>
    public class LayerMetaDataViewModel : ObservableObject
    {
        #region props

        ///<summary>层 ID</summary>
        public string LayerNodeId { get; set; }

        ///<summary>文件路径。</summary>
        public string FilePath { get; set; }

        ///<summary>行Id</summary>
        public int LineId { get; set; }

        #endregion

        #region commands

        public ICommand NavigationCommand { get; private set; }

        #endregion

        #region ctors

        public LayerMetaDataViewModel() : this(null, null, -1)
        {

        }

        public LayerMetaDataViewModel(string layerNodeId, string filePath, int lineid)
        {
            LayerNodeId = layerNodeId;
            FilePath = filePath;
            LineId = lineid;
            NavigationCommand = new RelayCommand(Navigation);
        }

        public LayerMetaDataViewModel(string layerNodeId, CodeMetaData metaData) : this(layerNodeId, metaData.FilePath, metaData.LineId)
        {

        }

        #endregion

        #region command methods

        private void Navigation()
        {
            var thisAddIn = CommunityToolkit.Mvvm.DependencyInjection.Ioc.Default.GetService(typeof(ThisAddIn)) as ThisAddIn;
            if (thisAddIn == null) return;
            thisAddIn.Navigate(FilePath, LineId);
        }

        #endregion
    }
}
